class Solution {
    public:
        int minFallingPathSum(vector<vector<int>> &matrix) {
            int n = matrix.size();
            int f[101][103]={0};
            memset(f, 0x3f, sizeof(f));
            for (int i = 0; i < n; i++)
                f[0][i + 1] = matrix[0][i];
            for (int r = 1; r < n; r++)
                for (int c = 0; c < n; c++)
                    f[r][c + 1] = min(min(f[r - 1][c], f[r - 1][c + 1]), f[r - 1][c + 2]) + matrix[r][c];
            return *min_element(f[n - 1] + 1, f[n - 1] + 1 + n);
        }
    };